package com.chujian.framework.starter.webmvc;

import com.chujian.framework.mybatis.IQueryDataAuthLoader;
import com.chujian.framework.web.interceptor.AccessorHandlerInterceptor;
import com.chujian.framework.web.interceptor.ConfigQueryDataAuthHandlerInterceptor;
import com.chujian.framework.web.interceptor.FromGatewayHandlerInterceptor;
import com.chujian.framework.web.interceptor.FuncDynamicHandlerInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author ：chujian
 * @since ：2020-08-13
 * spring mvc 的通用配置
 */
public class BaseWebMvcConfig implements WebMvcConfigurer {

    @Autowired(required = false)
    private IQueryDataAuthLoader queryDataAuthLoader;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 网关校验 拦截器
        registry.addInterceptor(new FromGatewayHandlerInterceptor()).addPathPatterns("/**");
        // 访问者 拦截器
        registry.addInterceptor(new AccessorHandlerInterceptor()).addPathPatterns("/**");
        // 功能动态信息解析 拦截器
        registry.addInterceptor(new FuncDynamicHandlerInterceptor()).addPathPatterns("/**");
        // 装配权限信息 拦截器
        registry.addInterceptor(new ConfigQueryDataAuthHandlerInterceptor(queryDataAuthLoader)).addPathPatterns("/**");
    }

}
